//============== Networked: SA - http://code.google.com/p/n-sa/ ==============
//
// File: CGame.cpp
// Project: Client
// Developers: bpeterson
// License: See LICENSE in root directory
//
//============================================================================

#include "StdInc.h"

CGame::CGame()
{
	// Unprotect everything
	DWORD oldProt;
    VirtualProtect((LPVOID)0x401000, 0x4A3000, PAGE_EXECUTE_READWRITE, &oldProt);

	// Determine game version
	eGameVersion version = FindGameVersion();
	switch(version)
	{
		case VERSION_11:
			MessageBox(NULL, "You have GTA: SA version 1.1 installed. Please downgrade it to version 1.0 to play Networked: SA.", "Invalid game version", MB_ICONEXCLAMATION);
            		ExitProcess(0);
			break;
		case VERSION_20:
			MessageBox(NULL, "You have GTA: SA version 2.0 installed. Please downgrade it to version 1.0 to play Networked: SA.", "Invalid game version", MB_ICONEXCLAMATION);
            		ExitProcess(0);
			break;
		case VERSION_UNKOWN:
			MessageBox(NULL, "Unkown version of GTA: SA detected. Networked: SA only supports version 1.0.", "Unkown game version", MB_ICONEXCLAMATION);
            		ExitProcess(0);
			break;
	}
}

CGame::~CGame()
{

}

eGameVersion CGame::GetGameVersion(void)
{
	return m_eGameVersion;
}

eGameVersion CGame::FindGameVersion(void)
{
	unsigned char ucAddress1 = *reinterpret_cast <unsigned char*> (0x748ADD);
	unsigned char ucAddress2 = *reinterpret_cast <unsigned char*> (0x748ADE);

	if(ucAddress1 == 0xFF && ucAddress2 == 0x53)
	{
		m_eGameVersion = VERSION_US_10;
	}
	else if(ucAddress1 == 0x0F && ucAddress2 == 0x84)
	{
		m_eGameVersion = VERSION_EU_10;
	}
	else if(ucAddress1 == 0xFE && ucAddress2 == 0x10)
	{
		m_eGameVersion = VERSION_11;
	}
	else
	{
		m_eGameVersion = VERSION_UNKOWN;
	}

	return m_eGameVersion;
}

// EOF